package king.dominic.jorc.ui;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;

import king.dominic.jlibrary.activity.OriginActivity;
import king.dominic.jlibrary.util.PermissionUtil;
import king.dominic.jorc.R;
import king.dominic.jorc.core.IdentityCard;

/**
 * Created by DominicKing on 2018/1/26.
 * ScanCardActivity
 */

public class ScanCardActivity extends OriginActivity {

    @SuppressLint("MissingPermission")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_framelayout);
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.container, ParseCardFromCameraFragment.newInstance(this, getIntent().getBooleanExtra("front", true)))
                .commit();
    }

    public static IdentityCard obtainCard(Intent data) {
        return ParseCardFromCameraFragment.obtainCard(data);
    }

    public static String obtainCardImage(Intent data) {
        return ParseCardFromCameraFragment.obtainCardImage(data);
    }

    public static boolean obtainCardFront(Intent data) {
        return ParseCardFromCameraFragment.obtainCardFront(data);
    }

    public static void startForResult(final OriginActivity activity, final boolean front, final int requestCode) {
        PermissionUtil.callMethod(activity, new String[]{Manifest.permission.CAMERA}, new Runnable() {
            @Override
            public void run() {
                activity.startActivityForResult(new Intent(activity, ScanCardActivity.class).putExtra("front", front),requestCode);
            }
        });
    }
}
